#include "HardwareProfile.h"

void KeyProc(void)
{
	unsigned int key;
	unsigned char x;
	key=KeyCheck();
	if(key==NoKey)
		return;	
	Beep_W=1;
	KeySoundTick=SystemTick;
	switch(key)
	{
	case Key_Clear:
		if(!gFlags.bSetting)
		{
			if(gFlags.bAlarm)
			{
				gFlags.bAlarm=0;
				WorkMinute=WFRomOneByte;
				WorkSecond=0;
				TMR2Times=0;
				TMR2=0;
				TMR2ON=1;
				Display_WorkShow();
			}
		}
		Alarm_ON_W=0;
		break;
	case Key_Reset:
		if(!gFlags.bSetting)
		{
			gFlags.bAlarm=0;
			WorkMinute=WFRomOneByte;
			WorkSecond=0;
			TMR2Times=0;
			TMR2=0;
			TMR2ON=1;
			Display_WorkShow();
		}
		break;
	case Key_Set:
		if(!gFlags.bSetting)
		{
			gFlags.bSetting=1;
			gFlags.bShow=0;
			Setting_WorkTime=WFRomOneByte;
			FlashTick=SystemTick;
			Display_SettingShow();
		}
		break;
	case Key_Up:
		if(gFlags.bSetting)
		{
			if(Setting_WorkTime<116)
			{
				Setting_WorkTime+=5;
				gFlags.bShow=1;
				Display_SettingShow();
			}			
		}
		break;
	case Key_Down:
		if(gFlags.bSetting)
		{
			if(Setting_WorkTime>5)
			{
				Setting_WorkTime-=5;
				gFlags.bShow=1;
				Display_SettingShow();
			}			
		}
		break;
	case Key_enter:
		if(gFlags.bSetting)
		{
			WFRomOneByte=Setting_WorkTime;
			gFlags.bSetting=0;
			SaveRomData();
			gFlags.bAlarm=0;
			WorkMinute=WFRomOneByte;
			WorkSecond=0;
			TMR2Times=0;
			TMR2=0;
			TMR2ON=1;
			Display_WorkShow();		
		}
		break;
	}
}


